﻿using System;
using System.Windows.Input;
using System.Xml.Linq;

using Perseus;
using Perseus.Xml;

using Hetymine.Executioner.Controls;
using Hetymine.Executioner.Data;

namespace Hetymine.Executioner.Triggers {
    public class HotKeyTrigger : HotKeyInfo, ITrigger {
        private HotKeyTriggerConfigurator _Configurator;

        #region ITrigger Members
        public bool IsEmpty {
            get { return (this.Key == Key.None); }
        }
        public bool IsSelected { get; set; }

        public void Load(XElement element) {
            this.HotKey = element.Value;
        }
        public XElement Save() {
            if (this.IsEmpty) {
                return null;
            }

            XElement xe = new XElement("HotKey");
            xe.Value = this.HotKey;

            return xe;
        }

        public IConfigurator<ITrigger> Configurator {
            get {
                if (this._Configurator == null) {
                    this._Configurator = new HotKeyTriggerConfigurator();
                }
                this._Configurator.InitializeConfig(this);
                return this._Configurator;
            }
        }

        public object Clone() {
            HotKeyTrigger t = (HotKeyTrigger)this.MemberwiseClone();
            t._Configurator = null;
            return t;
        }
        #endregion
    }
}
